<?php
namespace app\common\service;;

use think\facade\Db;

/**
 * Class MyOrder
 * @package app\common\service
 * 我的订单
 */
class UploadFile extends Base {

    static $AUTH_CHECK = false; //默认必须登录
    public function uploadimg(){
        $file = request()->file('file');

        $dir = UPLOAD_PATH;
        if (!($_exists = file_exists($dir))){
            $isMk = mkdir($dir,775,true);
        }
        $parentDir = date('Ymd');

        validate(['file'=>['fileExt:'.config('app.upload_type')]])->check(['file' => $file]);
        $savename = \think\facade\Filesystem::disk('public')->putFile('',$file);

        if($savename){
            $file_path = '/upload/'.str_replace("\\",'/',$savename);
        }else{
            $result = [
                'status' => 0,
                'msg' => $file->getError(),
                'data' => '',
            ];
            return $result;
        }
        $fiel_url = getCurUrl().'/'.$file_path;
        //图片上传oss
        $res = logic('OssLogic')->oss_upload($fiel_url);
        if($res){
            $fiel_url = $res;
        }
        $result = [
            'status' => 1,
            'msg' => '',
            'data' => $fiel_url,
            'url' => $fiel_url,
            'sortnum' => 0
        ];
        return $result;
    }

}
